import { Component } from 'cc';
import { BaseEventType } from '../Config/BaseEnum';
import { LoadingManager } from '../Manager/LoadingManager';
import { EventManager } from '../Manager/EventManager';
import type { PanelBase } from './PanelBase';
import { ModelBase } from './ModelBase';
/* eslint-disable */

export abstract class PanelModel extends ModelBase {
  /** 界面资源 */
  abstract readonly loadRes: string;
  curPanel?: Component | PanelBase;

  /** 打开界面 */
  Show(prop?: Record<any, any>): void {
    EventManager.Ins().emit(BaseEventType.GAME_SHOW_PANEL, this.loadRes, prop);
  }

  /** 不通过loading, 打开界面 */
  ShowPanel(prop?: Record<any, any>): void {
    EventManager.Ins().emit(BaseEventType.GAME_SHOW_PANEL_NOW, this.loadRes, prop);
  }

  /** 待会显示界面 */
  ShowPanelLater(prop?: Record<any, any>): void {
    EventManager.Ins().emit(BaseEventType.GAME_SHOW_PANEL_LATER, this.loadRes, prop);
  }

  /** 不受界面规则约束, 打开界面 */
  ShowPanelNode(prop?: Record<any, any>): void {
    EventManager.Ins().emit(BaseEventType.GAME_SHOW_PANEL_NODE, this.loadRes, prop);
  }

  /** 销毁界面节点并释放资源，但保留界面数据 */
  destroy(boo: boolean = false) {
    this.releaseDynamicRes();
    LoadingManager.Ins().releaseDynamicRes(this.loadRes);
    if (boo) {
      this.destroySingleton();
    }
  }
}
